/*
 * Copyright (C) 2008-2010 TrinityCore <http://www.trinitycore.org/>
 * Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/* ScriptData
SDName: Boss_Moira_Bronzbeard
SD%Complete: 100
SDComment:
SDCategory: Blackrock Depths
EndScriptData */

#include "ScriptPCH.h"
#include "blackrock_depths.h"

enum Spells
{
    SPELL_HEAL                                             = 10917,
    SPELL_RENEW                                            = 10929,
    SPELL_SHIELD                                           = 10901,
    SPELL_MINDBLAST                                        = 10947,
    SPELL_SHADOWWORDPAIN                                   = 10894,
    SPELL_SMITE                                            = 10934
};

class boss_moira_bronzebeard : public CreatureScript
{
public:
    boss_moira_bronzebeard() : CreatureScript("boss_moira_bronzebeard") { }

    CreatureAI* GetAI(Creature* pCreature) const
    {
        return new boss_moira_bronzebeardAI (pCreature);
    }

    struct boss_moira_bronzebeardAI : public ScriptedAI
    {
        boss_moira_bronzebeardAI(Creature *c) : ScriptedAI(c)
        {
            pInstance = c->GetInstanceScript();
        }

        InstanceScript *pInstance;

        uint32 uiHeal_Timer;
        uint32 uiRenew_Timer;
        uint32 uiMindBlast_Timer;
        uint32 uiShadowWordPain_Timer;
        uint32 uiSmite_Timer;

        void Reset()
        {
            uiHeal_Timer = urand(10000,12000);
            uiRenew_Timer = urand(12000,15000);
            uiMindBlast_Timer = urand(8000,12000);
            uiShadowWordPain_Timer = urand(2000,4000);
            uiSmite_Timer = urand(8000,10000);
        }

        void UpdateAI(const uint32 uiDiff)
        {
            //Return since we have no target
            if (!UpdateVictim())
                return;

            //MindBlast_Timer
            if (uiMindBlast_Timer <= uiDiff)
            {
                DoCast(me->getVictim(), SPELL_MINDBLAST);
                uiMindBlast_Timer = urand(8000,12000);
            } else uiMindBlast_Timer -= uiDiff;

            //ShadowWordPain_Timer
            if (uiShadowWordPain_Timer <= uiDiff)
            {
                DoCast(me->getVictim(), SPELL_SHADOWWORDPAIN);
                uiShadowWordPain_Timer = urand(12000,14000);
            } else uiShadowWordPain_Timer -= uiDiff;

            //Smite_Timer
            if (uiSmite_Timer <= uiDiff)
            {
                DoCast(me->getVictim(), SPELL_SMITE);
                uiSmite_Timer = urand(8000,10000);
            } else uiSmite_Timer -= uiDiff;
 
            if (Unit *pTarget = DoSelectLowestHpFriendly(40.0f))
            {
                if (uiHeal_Timer <= uiDiff)
                {
                    DoCast(pTarget, SPELL_HEAL);
                    uiHeal_Timer = urand(8000,10000);
                } else uiHeal_Timer -= uiDiff;

                if (uiRenew_Timer <= uiDiff)
                {
                    DoCast(pTarget, SPELL_RENEW);
                    uiRenew_Timer = urand(12000,15000);
                } else uiRenew_Timer -= uiDiff;
            }

            if (pInstance && pInstance->GetData(DATA_EMPEROR) == DONE)
            {
                me->setFaction(35);
                me->SetReactState(REACT_PASSIVE);
                EnterEvadeMode();
            }
            
            DoMeleeAttackIfReady();
        }
    };

};

void AddSC_boss_moira_bronzebeard()
{
    new boss_moira_bronzebeard();
}
